package model.semantics;

import model.State;

public class IfElseNode extends Node<Integer> {
    private Node<Integer> myExpr, myIfNode, myElseNode;

    public IfElseNode(Node<Integer> expr, Node<Integer> ifNode,
            Node<Integer> elseNode) {
        myExpr = expr;
        myIfNode = ifNode;
        myElseNode = elseNode;
    }

    @Override
    public Integer evaluate(State<Integer> state) {
        return myExpr.evaluate(state) > 0 ? myIfNode.evaluate(state)
                : myElseNode.evaluate(state);
    }

    @Override
    public String toString() {
        return String.format("(%s %s %s %s)", "ifelse", myExpr.toString(),
                myIfNode.toString(), myElseNode.toString());
    }

}
